<template>
  <div class="flow-chart-nav">
    <div class="flow-header">
      <!-- 空标题保留布局 -->
    </div>
    <div class="flow-header-title">数据处理流程</div>
    <div class="flow-chart">
      <div class="flow-step" v-for="step in steps" :key="step.id" @click="handleStepClick(step)">
        <div class="step-icon" :class="step.status">
          <i :class="step.icon"></i>
        </div>
        <div class="step-info">
          <h4>{{ step.title }}</h4>
          <p>{{ step.description }}</p>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'

const steps = ref([
  {
    id: 1,
    title: '数据接入',
    description: '连接数据源或上传本地文件',
    icon: 'el-icon-upload',
    status: 'active',
    component: 'DataImport'
  },
  {
    id: 2,
    title: '数据预处理',
    description: '清洗和转换数据',
    icon: 'el-icon-setting',
    status: 'waiting',
    component: 'DataProcess'
  },
  {
    id: 3,
    title: '数据分析',
    description: '运行分析模型',
    icon: 'el-icon-data-analysis',
    status: 'waiting',
    component: 'DataAnalysis'
  }
])

const emit = defineEmits(['step-change'])

const handleStepClick = (step) => {
  steps.value.forEach(s => {
    s.status = s.id === step.id ? 'active' : 'waiting'
  })
  // 直接触发父组件事件
  emit('step-change', step.component)

  // 同时派发自定义事件（兼容旧实现）
  const event = new CustomEvent('step-change', {
    detail: step.component,
    bubbles: true
  })
  document.dispatchEvent(event)
}
</script>

<style scoped>
.flow-chart-nav {
  width: 240px;
  background: #fff;
  border-right: 1px solid #e6e6e6;
  height: 100%;
  padding-top: 20px;
  /* 新增上边距 */
}


.flow-header {
  padding: 16px;
  border-bottom: 1px solid #f0f0f0;
}

.flow-menu {
  border-right: none;
}

.flow-chart {
  padding: 16px;
}

.flow-step {
  display: flex;
  margin-bottom: 16px;
  align-items: flex-start;
}

.step-icon {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 12px;
  background: #f5f5f5;
  color: #999;
}

.step-icon.active {
  background: #409eff;
  color: white;
}

.step-info h4 {
  margin: 0 0 4px 0;
  font-size: 14px;
}

.step-info p {
  margin: 0;
  font-size: 12px;
  color: #999;
}
</style>